﻿@model GoodAttrDTO
@{
    ViewBag.Title = "添加商品属性";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<style>
    /*日期的css开始*/
    body {
        padding: 20px;
    }

    .demo-input {
        padding-left: 10px;
        height: 38px;
        min-width: 262px;
        line-height: 38px;
        border: 1px solid #e6e6e6;
        background-color: #fff;
        border-radius: 2px;
    }

    .demo-footer {
        padding: 50px 0;
        color: #999;
        font-size: 14px;
    }

        .demo-footer a {
            padding: 0 5px;
            color: #01AAED;
        }
    /*日期的css结束*/
</style>

<!--获取日期js-->
<script src="~/common/laydate.js"></script>
@*<script src="laydate/laydate.js"></script>*@
<script>
    lay('#version').html('-v' + laydate.v);

    //执行一个laydate实例
    laydate.render({
        elem: '#test1' //指定元素
    });
</script>
<!--获取生产日期结束-->

<section class="layui-larry-box">
    <div class="larry-personal">
        <header class="larry-personal-tit">
            <span>添加商品属性</span>
        </header><!-- /header -->

        <div class="larry-personal-body clearfix">
            <form class="layui-form col-lg-5" action="" method="post">
                <input type="hidden" name="Id" value="@Model.Id" />
                <input type="hidden" name="GoodId" value="@Model.GoodId" />
                <div class="layui-form-item">
                    <label class="layui-form-label">生产编号</label>
                    <div class="layui-input-block">
                        <input name="ProNumber" value="@Model.ProNumber" type="text" autocomplete="off" class="layui-input" placeholder="请输入生产编号">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">商品</label>
                    <div class="layui-input-block">
                        <input name="GoodId" value="@Model.GoodName" disabled type="text" autocomplete="off" class="layui-input" placeholder="请输入商品id">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">有效期</label>
                    <div class="layui-inline">
                        <input type="text" value="@Model.ValidTime" name="ValidTime" lay-verify="required" autocomplete="off" class="layui-input " placeholder="请输入该商品有效期">
                    </div>

                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">级别</label>
                        <div class="layui-input-block">
                            <input name="Level" value="@Model.Level" type="text" autocomplete="off" class="layui-input" placeholder="请输入生产编号">
                        </div>
                     
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">生产日期</label>
                    <div class="layui-input-block">
                        <input type="text" value="@Model.ProduceTime" name="ProduceTime" class="demo-input" placeholder="请选择日期" id="test1">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">工艺描述</label>
                    <div class="layui-input-block">
                        <textarea placeholder="既然选择了远方，便只顾风雨兼程；路漫漫其修远兮，吾将上下而求索" value="" class="layui-textarea" name="ArtDesc">@Model.ArtDesc</textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="editBtn">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</section>


@section FooterScript{
    <script src="~/common/laydate.js"></script>
    @*<script type="text/javascript" src="common/laydate.js"></script>*@
    <script src="~/common/layui/layui.all.js"></script>
    @*<script type="text/javascript" src="common/layui/layui.all.js"></script>*@
    <script type="text/javascript">

        //执行一个laydate实例
        laydate.render({
            elem: '#datetime' //指定元素
        });

        layui.config({
            base: "js/"
        }).use(['form', 'layer', 'jquery', 'layedit'], function () {
            var form = layui.form,
                layer = parent.layer === undefined ? layui.layer : parent.layer,
                laypage = layui.laypage,
                layedit = layui.layedit,
                $ = layui.jquery;


            //数据验证
            form.verify({
                username: function (value, item) { //value：表单的值、item：表单的DOM对象
                    if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                        return '用户名不能有特殊字符';
                    }
                    if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                        return '用户名首尾不能出现下划线\'_\'';
                    }
                    if (/^\d+\d+\d$/.test(value)) {
                        return '用户名不能全为数字';
                    }
                }

                //我们既支持上述函数式的方式，也支持下述数组的形式
                //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
                , pass: [
                    /^[\S]{6,12}$/
                    , '密码必须6到12位，且不能出现空格'
                ]
            });


            //此处的addNew是38行代码中提交按钮的 lay-filter属性
            form.on("submit(editBtn)", function (data) {

                var index = top.layer.msg('数据提交中，请稍候', { icon: 16, time: false, shade: 0.8 });

                var formData = $(".layui-form").serialize();    //表单数据

                $.ajax({
                    url: "/GoodAttr/Edit",
                    type: "post",
                    dataType: "json",
                    data: formData,
                    traditional: true,//这里设置为true
                    success: function (res) {
                        if (res.status == "ok") {
                            layer.msg("添加成功", {
                                icon: 1, time: 1000, end: function () {
                                    top.layer.close(index);
                                    layer.closeAll("iframe");
                                    //刷新父页面
                                    parent.location.reload();
                                }
                            });



                        } else {
                            layer.msg("添加失败:" + res.errorMsg, {
                                icon: 5, time: 1000, end: function () {
                                    top.layer.close(index);
                                    layer.closeAll("iframe");
                                    //刷新父页面
                                    parent.location.reload();
                                }
                            });
                        }
                    },
                    error: function () {
                        layer.msg("网络请求失败", {
                            icon: 5, time: 2000, end: function () {
                                top.layer.close(index);
                                layer.closeAll("iframe");
                                //刷新父页面
                                parent.location.reload();
                            }
                        });
                    }
                });

                return false;
            })

        })

    </script>

}